<template>
  <el-row v-if="showForPro()" :gutter="50" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="alert" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">告警</div>
          <count-to :start-val="0" :end-val="alarm" :duration="3200" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="device" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">设备</div>
          <count-to :start-val="0" :end-val="device" :duration="2600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="asset" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">资产</div>
          <count-to :start-val="0" :end-val="asset" :duration="3000" class="card-panel-num"/>
        </div>
      </div>
    </el-col>

    <!--<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="handleSetLineChartData('shoppings')">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="gas" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">煤气告警</div>
          <count-to :start-val="0" :end-val="13600" :duration="3600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>-->
  </el-row>

  <el-row v-else-if="showForSup()" :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="alert" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">告警</div>
          <count-to :start-val="0" :end-val="alarm" :duration="3200" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="department" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">下属机构</div>
          <count-to :start-val="0" :end-val="subordinate " :duration="2600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="danger" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">危险源</div>
          <count-to :start-val="0" :end-val="hazards" :duration="3000" class="card-panel-num"/>
        </div>
      </div>
    </el-col>

    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="building" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">建筑</div>
          <count-to :start-val="0" :end-val="building" :duration="3600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>

    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-site">
          <svg-icon icon-class="site" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">站点</div>
          <count-to :start-val="0" :end-val="site" :duration="2600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>

    <el-col :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-msg">
          <svg-icon icon-class="message" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">消息</div>
          <count-to :start-val="0" :end-val="message" :duration="2600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
  </el-row>

  <el-row v-else :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="water" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">水务告警</div>
          <count-to :start-val="0" :end-val="waterAlarm" :duration="2600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="electricity" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">电力告警</div>
          <count-to :start-val="0" :end-val="electricityAlarm" :duration="3000" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="fire" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">火灾告警</div>
          <count-to :start-val="0" :end-val="fireAlarm" :duration="3200" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="gas" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">煤气告警</div>
          <count-to :start-val="0" :end-val="gasAlarm" :duration="3600" class="card-panel-num"/>
        </div>
      </div>
    </el-col>
  </el-row>

</template>

<script>
import CountTo from 'vue-count-to'
import { statistics } from '@/api/fire/home/index'

export default {
  components: {
    CountTo
  },
  data() {
    return {
      waterAlarm: 0,
      electricityAlarm: 0,
      gasAlarm: 0,
      fireAlarm: 0,
      alarm: 0,
      device: 0,
      asset: 0,
      subordinate: 0,
      hazards: 0,
      building: 0,
      site: 0,
      message: 0
    }
  },
  created() {
    this.getDate()
  },
  methods: {
    handleSetLineChartData(type) {
      this.$emit('handleSetLineChartData', type)
    },
    getDate() {
      statistics(this.listQuery).then(response => {
        console.log(response)
        this.waterAlarm = response.data.context.waterAlarm
        this.electricityAlarm = response.data.context.electricityAlarm
        this.gasAlarm = response.data.context.gasAlarm
        this.fireAlarm = response.data.context.fireAlarm
        this.alarm = response.data.context.alarm
        this.divice = response.data.context.device
        this.asset = response.data.context.asset
        this.subordinate = response.data.context.subordinate
        this.hazards = response.data.context.hazards
        this.building = response.data.context.building
        this.site = response.data.context.site
        this.message = response.data.context.message
      })
    },
    showForPro() {
      console.log(this.$store.getters.roles[0])
      if (this.$store.getters.roles[0] === 'proprietor') {
        return true
      }
    },
    showForSup() {
      console.log(this.$store.getters.roles[0])
      if (this.$store.getters.roles[0] === 'supervisor') {
        return true
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.panel-group {
  margin-top: 18px;
  .card-panel-col{
    margin-bottom: 32px;
  }
  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }
      .icon-people {
         background: #36a3f7;
      }
      .icon-message {
        background: #ffff66;
      }
      .icon-money {
        background: #f4516c;
      }
      .icon-shopping {
        background: #8a8a8a
      }
      .icon-msg {
        background: #6cc980
      }
      .icon-site {
        background: #d16f19
      }
    }
    .icon-people {
      color: #36a3f7;
    }
    .icon-message {
      color: #ffff66;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shopping {
      color: #8a8a8a
    }
    .icon-msg {
      color: #6cc980
    }
    .icon-site {
      color: #d16f19
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>
